(define (make-interval a b)
    (cons a b)
)
(define (lower-bound z)
    (car z)
)
(define (upper-bound z)
    (cdr z)
)

(define (print-interval x)
    (newline)
    (display "[")
    (display (lower-bound x))
    (display ",")
    (display (upper-bound x))
    (display "]")
)

(define (mul-interval x y)
    (let (
        (x1 (lower-bound x))
        (x2 (upper-bound x))
        (y1 (lower-bound y))
        (y2 (upper-bound y))        
        )
        (cond 
            ((and (< x1 0) (< x2 0) (< y1 0) (< y2 0))   (make-interval (* x2 y2) (* x1 y1)) )
            ((and (< x1 0) (< x2 0) (< y1 0) (>= y2 0))  (make-interval (* x1 y2) (* x1 y1)) )
            ((and (< x1 0) (< x2 0) (>= y1 0) (>= y2 0)) (make-interval (* x1 y2) (* x2 y1)) )
            
            ((and (< x1 0) (>= x2 0) (< y1 0) (< y2 0))  (make-interval (* x2 y1) (* x1 y1)) )
            ;大小判断有两种情况
            ((and (< x1 0) (>= x2 0) (< y1 0) (>= y2 0)) (make-interval 
                                                            (min (* x1 y2) (* x2 y1))
                                                            (max (* x1 y1) (* x2 y2))
                                                        ))
            ((and (< x1 0) (>= x2 0) (>= y1 0) (>= y2 0)) (make-interval (* x1 y2) (* x2 y2)) )

            ((and (>= x1 0) (>= x2 0) (< y1 0) (< y2 0))  (make-interval (* x2 y1) (* x1 y2)))
            ((and (>= x1 0) (>= x2 0) (< y1 0) (>= y2 0)) (make-interval (* x2 y1) (* x2 y2)))
            ((and (>= x1 0) (>= x2 0) (>= y1 0) (>= y2 0)) (make-interval (* x1 y1) (* x2 y2)))
            (else (error "it shoudn't be happend" x y ))
        )
    )
)
(define interval_1 
    (make-interval -2 -1)
)
(define interval_2 
    (make-interval -2 3)
)
(define interval_3 
    (make-interval 2 3)
)
(print-interval (mul-interval interval_1 interval_1 ))
(print-interval (mul-interval interval_1 interval_2 ))
(print-interval (mul-interval interval_1 interval_3 ))

(print-interval (mul-interval interval_2 interval_1 ))
(print-interval (mul-interval interval_2 interval_2 ))
(print-interval (mul-interval interval_2 interval_3 ))

(print-interval (mul-interval interval_3 interval_1 ))
(print-interval (mul-interval interval_3 interval_2 ))
(print-interval (mul-interval interval_3 interval_3 ))

(exit)